package cn.edu.gduf.luowowo.mgrsite.web.controller;

import cn.edu.gduf.luowowo.article.domain.Travel;
import cn.edu.gduf.luowowo.article.query.TravelQuery;
import cn.edu.gduf.luowowo.article.service.ITravelService;
import cn.edu.gduf.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/travel")
public class TravelController {
    @Reference
    private ITravelService travelService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") TravelQuery qo) {
        //pageInfo 查询所有游记为公开状态
        qo.setIsPublic(true);
        model.addAttribute("pageInfo", travelService.query(qo));
        return "travel/list";
    }

    @RequestMapping("/content")
    @ResponseBody
    public Object content(Long id) {
        return travelService.getContent(id);
    }

    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(Travel travel) {
        travelService.changeState(travel);
        return AjaxResult.SUCCESS;
    }
}
